package com.qianli.cashmama.trade.client.trade.request;


import com.fqgj.common.api.ParamsObject;
import com.fqgj.exception.common.ApplicationException;
import org.apache.commons.lang.StringUtils;

import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: sm
 * Date: 2017/7/24
 * Time: 上午9:55
 */
public class PayResultRequest extends ParamsObject {
    /**
     * 外部订单号
     */
    private String tradeNo;
    /**
     * 打款结果
     */
    private boolean paySuccess;
    /**
     * 错误码
     */
    private String resultCode;
    /**
     * 错误信息
     */
    private String resultMsg;
    /**
     * 打款成功日期
     */
    private Date receivedDate;
    /**
     * 支付系统流水号
     */
    private String payBizNo;
    /**
     * 资金方编号
     */
    private Integer capitalCode;
    /**
     * 是否重试 true: to ReBind Card ; false: to Close Order
     */
    private boolean payRetry;

    public PayResultRequest() {
    }

    public PayResultRequest(boolean paySuccess, Date receivedDate) {
        this.paySuccess = paySuccess;
        this.receivedDate = receivedDate;
        this.resultMsg = paySuccess ? "SUCCESS" : "FAILED";
    }

    public String getTradeNo() {
        return tradeNo;
    }

    public PayResultRequest setTradeNo(String tradeNo) {
        this.tradeNo = tradeNo;
        return this;
    }

    public boolean getPaySuccess() {
        return paySuccess;
    }

    public PayResultRequest setPaySuccess(boolean paySuccess) {
        this.paySuccess = paySuccess;
        return this;
    }

    public String getResultCode() {
        return resultCode;
    }

    public PayResultRequest setResultCode(String resultCode) {
        this.resultCode = resultCode;
        return this;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public PayResultRequest setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
        return this;
    }

    public Date getReceivedDate() {
        return receivedDate;
    }

    public PayResultRequest setReceivedDate(Date receivedDate) {
        this.receivedDate = receivedDate;
        return this;
    }

    public String getPayBizNo() {
        return payBizNo;
    }

    public PayResultRequest setPayBizNo(String payBizNo) {
        this.payBizNo = payBizNo;
        return this;
    }

    public Integer getCapitalCode() {
        return capitalCode;
    }

    public PayResultRequest setCapitalCode(Integer capitalCode) {
        this.capitalCode = capitalCode;
        return this;
    }

    public boolean getPayRetry() {
        return payRetry;
    }

    public PayResultRequest setPayRetry(boolean payRetry) {
        this.payRetry = payRetry;
        return this;
    }

    @Override
    public void validate() {
        if (StringUtils.isEmpty(tradeNo) || receivedDate == null) {
            throw new ApplicationException("Parameter error");
        }
    }
}
